#!/usr/bin/python
#coding: utf-8
#Boa:Dialog:CPXX_DLG

import wx
import current

def create(parent):
    return CPXX_DLG(parent)

[wxID_CPXX_DLG, wxID_CPXX_DLGBUTTON1, wxID_CPXX_DLGBUTTON2, 
 wxID_CPXX_DLGCPCB_TC, wxID_CPXX_DLGCPDM_TC, wxID_CPXX_DLGCPJIAGE_TC, 
 wxID_CPXX_DLGCPMC_TC, wxID_CPXX_DLGSTATICTEXT1, wxID_CPXX_DLGSTATICTEXT2, 
 wxID_CPXX_DLGSTATICTEXT3, wxID_CPXX_DLGSTATICTEXT4, 
] = [wx.NewId() for _init_ctrls in range(11)]

class CPXX_DLG(wx.Dialog):
    modify=False
    
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_CPXX_DLG, name=u'CPXX_DLG',
              parent=prnt, pos=wx.Point(339, 275), size=wx.Size(365, 324),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'\u4ea7\u54c1\u4fe1\u606f')
        self.SetClientSize(wx.Size(357, 290))

        self.staticText1 = wx.StaticText(id=wxID_CPXX_DLGSTATICTEXT1,
              label=u'\u4ea7\u54c1\u540d\u79f0\uff1a', name='staticText1',
              parent=self, pos=wx.Point(40, 24), size=wx.Size(60, 14), style=0)

        self.staticText2 = wx.StaticText(id=wxID_CPXX_DLGSTATICTEXT2,
              label=u'\u4ea7\u54c1\u4ee3\u7801\uff1a', name='staticText2',
              parent=self, pos=wx.Point(40, 72), size=wx.Size(60, 14), style=0)

        self.staticText3 = wx.StaticText(id=wxID_CPXX_DLGSTATICTEXT3,
              label=u'\u4ef7\u3000\u3000\u683c\uff1a', name='staticText3',
              parent=self, pos=wx.Point(40, 112), size=wx.Size(60, 14),
              style=0)

        self.staticText4 = wx.StaticText(id=wxID_CPXX_DLGSTATICTEXT4,
              label=u'\u6210\u3000\u3000\u672c\uff1a', name='staticText4',
              parent=self, pos=wx.Point(40, 152), size=wx.Size(60, 14),
              style=0)

        self.cpmc_tc = wx.TextCtrl(id=wxID_CPXX_DLGCPMC_TC, name=u'cpmc_tc',
              parent=self, pos=wx.Point(120, 24), size=wx.Size(136, 22),
              style=0, value=u'')

        self.cpdm_tc = wx.TextCtrl(id=wxID_CPXX_DLGCPDM_TC, name=u'cpdm_tc',
              parent=self, pos=wx.Point(120, 72), size=wx.Size(136, 22),
              style=0, value=u'')

        self.cpjiage_tc = wx.TextCtrl(id=wxID_CPXX_DLGCPJIAGE_TC,
              name=u'cpjiage_tc', parent=self, pos=wx.Point(120, 112),
              size=wx.Size(136, 22), style=0, value=u'')

        self.cpcb_tc = wx.TextCtrl(id=wxID_CPXX_DLGCPCB_TC, name=u'cpcb_tc',
              parent=self, pos=wx.Point(120, 152), size=wx.Size(136, 22),
              style=0, value=u'')

        self.button1 = wx.Button(id=wxID_CPXX_DLGBUTTON1, label=u'\u786e\u5b9a',
              name='button1', parent=self, pos=wx.Point(80, 216),
              size=wx.Size(75, 24), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnOKADD, id=wxID_CPXX_DLGBUTTON1)

        self.button2 = wx.Button(id=wxID_CPXX_DLGBUTTON2, label=u'\u53d6\u6d88',
              name='button2', parent=self, pos=wx.Point(208, 216),
              size=wx.Size(75, 24), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnCanle, id=wxID_CPXX_DLGBUTTON2)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        #self.tempmingch=self.cpmc_tc.GetValue()

    def OnOKADD(self, event):
        #event.Skip()
        session=current.CreateSession()
        
        cpmc=self.cpmc_tc.GetValue()
        if cpmc=='':
            wx.MessageBox('a')
            return
        
        cpdm=self.cpdm_tc.GetValue()
        cpjiage=self.cpjiage_tc.GetValue()
        cpcb=self.cpcb_tc.GetValue() 
        if CPXX_DLG.modify==True:
            wx.MessageBox(u'修改')
            CPXX_DLG.modify=False
            #cur=session.query(current.cpxx).filter_by(**{'mingch':self.tempmingch}).first() 
            cur=session.query(current.cpxx).filter_by(**{'id':self.tempmingch}).first()
            cur.mingch=cpmc
            cur.key=cpdm
            cur.jiage=cpjiage
            cur.chengben=cpcb 
            
            
            
        else:
            cur=current.cpxx(cpmc,cpdm,cpjiage,cpcb)
            current.InsertOb(cur)
             
        current.CommitSession(session)     
        current.CloseSession(session)
        wx.MessageBox(u'完成!')
        self.Destroy()

        
    def OnCanle(self, event):
        self.Destroy()
